package com.ask.handler;

import com.ask.dto.Result;
import com.ask.exception.BaseException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 基类异常处理器
     * @param ex
     * @return
     */
    @ExceptionHandler(BaseException.class)
    public Result baseExceptionHandler(BaseException ex) {
        String message = ex.getMessage();
        log.error("错误消息：{}", message);
        return Result.fail(message);
    }

}
